<?php
session_start() ;
if(!isset($_SESSION["login"]) || $_SESSION["login"] == "")
{   
  header("Location: index.php?error=4") ;
}?>

<html>
<head>
<title>Administration</title>
 <link rel="stylesheet" type="text/css" href="style.css" >  
</head>

<body>
<?php require("menu.php");
require("fonctions.php");
$code=$_GET["error"];
?>
<br></br>
<br>
<?php echo error_message($code);?>
<table  width="500">
<tr>
<td><a class="bouton" href="lv_add_user.php?cur=2">Ajouter un nouveau utilisateur</a></td>
</tr>
</table>
<br></br>
<table  width="350" >
<tr>
	<td class="tab_dis_head" colspan="2">LISTE DES UTILISATEURS</td>
</tr>
</table>
<br>
<table  class="tab_dis_contact">
<tr>
<td class="tab_dis_head">ID</td>
<td class="tab_dis_head">NOM</td>
<td class="tab_dis_head">PRENOM</td>
<td class="tab_dis_head">IDENTIFIANT</td>
<td class="tab_dis_head">PROFIL</td>
<td class="tab_dis_head">ACTION</td>
</tr>
<?php 
$sql="select * from users";
$res = mysql_query($sql);

while($r = mysql_fetch_object($res)){?>

<tr>
<td class="tab_dis_data"><?php echo $r->id;?></td>
<td class="tab_dis_data"><?php echo $r->nom;?></td>
<td class="tab_dis_data"><?php echo $r->prenom;?></td>
<td class="tab_dis_data"><?php echo $r->login;?></td>
<td class="tab_dis_data"><?php echo $r->profil;?></td>
<td class="tab_dis_data"><a href="lv_ges_user.php?action=mod_user&id_user=<?php echo $r->id?>&cur=2" >Modifier</a> / 
<a href="controler.php?action=sup_user&id_user=<?php echo $r->id?>" >Supprimer</a>
/ 
<?php if($r->profil=="MAN" or $r->profil=="DIS" or $r->profil=="RQ"){?>
<a href="lv_affected_user.php?cur=2&id_user=<?php echo"$r->id";?>&profil=<?php echo $r->profil;?>">affecter</a>
<?php }?>
</td>
</tr>
<?php }?>
</table>


<?php 
$action = $_GET["action"];
$id_user = $_GET["id_user"];
if($action=="mod_user"){
$sql="select * from users where id=$id_user";
$res = mysql_query($sql);
$r=mysql_fetch_object($res);
	
	?>

<form action="controler.php?action=mod_user" method=post>
<input name="id_user" type="hidden" value="<?php echo $id_user;?>">
<table  width="500">

<tr>
	<td>Nom</td><td><input type="text" name="nom" value="<?php echo $r->nom;?>"></td>
</tr>
<tr>
	<td>Pr&eacute;nom</td><td><input type="text" name="prenom" value="<?php echo $r->prenom;?>"></td>
</tr>

<tr>
	<td>Profil</td><td>
	<select name="profil">
		<option value="0"></option>
		<option value="LVDC" <?php if($r->profil=="LVDC") echo "selected";?>>LVDC</option>
		<option value="RT" <?php if($r->profil=="RT") echo "selected";?>>Renault Trucks</option>
		<option value="MAN" <?php if($r->profil=="MAN") echo "selected";?>>Manager</option>
		<option value="RT" <?php if($r->profil=="RT") echo "selected";?>>RT</option>
		<option value="RQ" <?php if($r->profil=="RQ") echo "selected";?>>Responsable qualit&eacute;</option>
		<option value="DIS" <?php if($r->profil=="DIS") echo "selected";?>>Etablissement</option>
	</select></td>
</tr>
<tr>
	<td>Identifiant</td><td><input type="text" name="login" value="<?php echo $r->login;?>"></td>
</tr>
<tr>
	<td>Mot de passe</td><td><input type="text" name="password" value="<?php echo $r->password;?>"></td>
</tr>
<tr>
	<td colspan=2 align=center><input type="submit" name="valider" value="Cr&eacute;er utilisateur"></td>
</tr>
</table>
</form>

<?php 	
}
?>
</body>

</html>
